<?php
/**
 *  💡 免责声明：本软件不得用于商业用途，仅做学习交流
 *  ⚠️ 权利声明：本软件由版权人提供产品技术支持
 *  📅 项目编号：NX2025-0135
 */
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateFootprintsTable extends Migration
{
    /**
     * Run the migrations.
     */
    public function up()
    {
        Schema::create('footprints', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('user_id')->comment('用户ID');
            $table->unsignedBigInteger('product_id')->comment('商品ID');
            $table->unsignedInteger('view_count')->default(1)->comment('累计浏览次数');
            $table->timestamp('last_viewed_at')->comment('最后浏览时间');
            $table->unique(['user_id', 'product_id'], 'user_product_unique');
            $table->index('last_viewed_at', 'last_viewed_index');
            // 软删除支持
            $table->softDeletes()->comment('删除时间');
            $table->timestamps();
        });
        \Illuminate\Support\Facades\DB::statement("ALTER TABLE `footprints` comment '足迹'");
    }

    /**
     * Reverse the migrations.
     */
    public function down()
    {
        Schema::dropIfExists('footprints');
    }
}
